<?php
error_reporting(0);
require_once("includes/pagetop.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}

$patharr=explode("/",$_SERVER["REQUEST_URI"]);

$lastvars=end($patharr);

$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);
if(!(isset($_REQUEST['t']) && trim($_REQUEST['t'])!=''))
{
    redirect("home.php");
}

$dnauserqry="select * from af_users where  	User_ID=:afuserid and Profile_Status=0 ";
$condition[":afuserid"]=$_SESSION['Allyfolio_User_ID'];
$dnauserinfo=$pdodbobj->fetch_array($pdodbobj->query($dnauserqry,$condition));

if(count($dnauserinfo)==0)
{
    redirect($_SERVER["HTTP_REFERER"]);
}

if($_POST && $_POST["submit_button"]!="")
{
	include_once "ajax_dna_album.php";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | DNA </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>



<script src="js/jquery.placeholder.js"></script>

<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	

	}

	.new tr td{ vertical-align:top}

	

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

	

</style>

</head>



<body>



	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<div class="wrapper row1">
    
    <?php
    require_once("includes/dnaheader.php");
    
    ?>

    <div class="clearfix"></div>  

    </div>

    <div class="clearfix"></div>

    <!--=================Header end=======================-->

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <?php include_once("dna_top.php"); ?>
        <style>
        	.dna-profile-hidden{
				display: none;
			}
		</style>
		<?php
			$menuType="IMAGE";
			include_once("dna_photo_video_top.php"); 
		?>
		<div class="dna_form">
			<form id="image_form" name="image_form" enctype="multipart/form-data" method="post" onsubmit="return checkValidation();">
				<table width="100%" border="0" cellspacing="10px" cellpadding="10px" class="new" style="font-size:16px; font-weight:bold;border-collapse:separate !important;">
					<tr valign="top">
						<td valign="top"><span class="blue_lable">Album Name</span></td>
						<td valign="top">
							<input type="text" class="dna_tbox" id="Album_Name" name="Album_Name" value="" />
						</td>
					</tr>
					<tr valign="top">
						<td valign="top"><span class="blue_lable">Upload Photos</span></td>
						<td valign="top">
							<!--<a href="javascript:void(0);" onclick="return openFile();">Upload Photos</a>-->
						   	<input type="file" name="selectedFile[]" id="selectedFile" style="display:block;" multiple accept="image/*"  /><!-- onChange="return upload();" 
							<div id="image_loader_div" style="display:none;"><img src="images/LoadingBar.gif" width="64px" height="64px"/></div>-->
						</td>
					</tr>
					<tr valign="top">
						<td colspan="2" valign="top" align="center">
							<input class="up_btn" type="submit" name="submit_button" id="submit_button" value="Create Album">
						</td>
					</tr>
				</table>
				<input type="hidden" name="Media_Type" id="Media_Type" value="IMAGE">				
			</form>
		</div>

<div class="clearfix"></div>

       </div>  

</div>

</div>

<div class="clearfix"></div>

<!--=================Body Contain end=======================-->

</div>
<script>
	function checkValidation()
	{
		if($("#Album_Name").val().trim()=="")
		{
			$("#Album_Name").focus();
			alertify.alert("Please enter album name.");
			return false;
		}
		else if($("#selectedFile").val().trim()=="")
		{
			alertify.alert("Please upload Image.");
			return false;
		}
		else{
			return true;
		}
		return false;
	}
	function openFile()
	{
		$("#selectedFile").trigger("click");
		//document.getElementById('selectedFile').click(); 
	}
	
	function upload()
	{
		if(document.getElementById("selectedFile").value!="")
		{
			document.getElementById("image_loader_div").style.display="";
			formdata = false;
			if (window.FormData) {
				formdata = new FormData(document.getElementById("image_form"));
			}
		
			var xmlhttp;
					
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
				xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
				if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{	
					var res=xmlhttp.responseText;	
					resArr=res.split("|~|");
					if(resArr[0]=="SUCCESS")
					{
						var divContent='<div class="upVid">';
						divContent +='<div class="vid"><a href="'+resArr[1]+'" class="PagePhotoGallery" data-fancybox-group="PagePhotoGallery"><img src="uploads/image_crop.php?image=/'+resArr[1]+'&width=93&height=91&cropratio=93:91" /></a></div>';
						divContent +='</div>';
						
						document.getElementById("page_photos_div").innerHTML=document.getElementById("page_photos_div").innerHTML+divContent;
						document.getElementById("image_loader_div").style.display="none";
					}
					else
					{
						document.getElementById("image_loader_div").style.display="none";
						alertify.alert(resArr[1]);
					}
				}
			}	
			xmlhttp.open("POST","ajax_dna_album.php",true);
			xmlhttp.send(formdata);
		}
	}
	
	function deletePageMedia(mediaID, page)
	{
		var xmlhttp;
					
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{	
				var res=xmlhttp.responseText;	
				resArr=res.split("|~|");
				if(resArr[0]=="SUCCESS")
				{
					document.getElementById("media_upload_div_"+mediaID).innerHTML="";
					document.getElementById("media_upload_div_"+mediaID).style.display="none";
					document.getElementById("image_loader_div").style.display="none";
				}
				else
				{
					document.getElementById("image_loader_div").style.display="none";
					alertify.alert(resArr[1]);
				}
			}
		}	
		xmlhttp.open("POST","ajax_page_photos.php?purpose=delete&mediaID="+mediaID+"&page="+page,true);
		xmlhttp.send();
	}


<?php
if(isset($msg_success) && $msg_success!="")
{
    ?>
    alertify.alert("<?php echo $msg_success; ?>");
    <?php
}

if(isset($msg_error) && $msg_error!="")
{
    ?>
    alertify.alert("<?php echo $msg_error; ?>");
    <?php
}
?>

	$(document).ready(function(){
		$('.PagePhotoGallery').fancybox();
	});
</script>    
<?php
    require_once("includes/footer.php");
?>